import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet(name = "OrderSmsServlet",urlPatterns = "/ordersms.do")
public class OrderSmsServlet extends HttpServlet {

    private static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String successJson="{\"msg\":\"success\",\"status\":true}";
        String failJson="{\"msg\":\"fail\",\"status\":false}";
        String osn=request.getParameter("osn");
        String smscode=request.getParameter("smscode");
        System.out.println(sdf.format(new Date())+" smscode:"+smscode+" osn:"+osn);
        if ("".equals(osn)||"".equals(smscode)||osn==null||smscode==null){
            responseContent(response,failJson);
        }else{
            responseContent(response,successJson);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");
        doPost(request,response);
    }

    private void responseContent(HttpServletResponse response,String content) throws IOException {
        PrintWriter writer=response.getWriter();
        writer.write(content);
        writer.close();
    }
}
